/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
 *
 * @author NS
 */
public class User_Add {
    private Connection conn;
    public User_Add(Connection conn){
        this.conn = conn;
    }
    public String add(UserInfo usr){
        Statement select;
        try{
            select = conn.createStatement();
            
            System.out.println("CREATE USER " + usr.getUsername() +
                                  " IDENTIFIED BY " + usr.getPwd() +
                                  " DEFAULT TABLESPACE " + usr.getDefTbspace() +
                                  " TEMPORARY TABLESPACE " + usr.getTmpTbspace()+
                                  " QUOTA " + usr.getQuota() + " ON " + usr.getDefTbspace()+ 
                                  " ACCOUNT " + usr.getAccStatus()+
                                  " PROFILE " + usr.getProfile());
            
            select.executeUpdate("CREATE USER " + usr.getUsername() +
                                  " IDENTIFIED BY " + usr.getPwd() +
                                  " DEFAULT TABLESPACE " + usr.getDefTbspace() +
                                  " TEMPORARY TABLESPACE " + usr.getTmpTbspace()+
                                  " QUOTA " + usr.getQuota() + " ON " + usr.getDefTbspace()+ 
                                  " ACCOUNT " + usr.getAccStatus()+
                                  " PROFILE " + usr.getProfile());
            
            
            System.out.println("INSERT INTO USERTBL VALUES(" +
                                    usr.getID() + ",'" + 
                                    usr.getUsername().toUpperCase() + "','" +
                                    usr.getPwd() + "','" +
                                    usr.getDefTbspace() + "','" +
                                    usr.getTmpTbspace() + "','" + 
                                    usr.getAccStatus() + "','" +
                                    usr.getQuota() + "','" +
                                    usr.getProfile() + "','"+
                                    usr.getRole() + "')");
            select.executeUpdate("INSERT INTO USERTBL VALUES(" +
                                    usr.getID() + ",'" + 
                                    usr.getUsername().toUpperCase() + "','" +
                                    usr.getPwd() + "','" +
                                    usr.getDefTbspace() + "','" +
                                    usr.getTmpTbspace() + "','" + 
                                    usr.getAccStatus() + "','" +
                                    usr.getQuota() + "','" +
                                    usr.getProfile() + "','"+
                                    usr.getRole() + "')");
            return "success";
            
        }catch(SQLException e){
            return e.getMessage();
        }
    }
}
